App({
  routerGuard: {
    getThis() {
      return this
    },
    beforeEach(to, from, next) {
      // 在进入页面之前执行的逻辑
      console.log('before each');
      console.log(this.getThis().isAuthenticated);
      // 判断是否满足访问条件：isAuthenticated()为自定义方法，你可以改成自己任意的方法或判断
      if (!this.isAuthenticated) {
        wx.navigateTo({
          url: '/pages/login/login'
        });
      } else {
        next();
      }
    },
    afterEach(to, from) {
      // 在离开页面之后执行的逻辑
      console.log('after each');
    }
  },
  onLaunch() {
    let user = wx.getStorageSync('user')
    if (user)
      this.globalData.isAuthenticated = true
  },
  globalData: {
    userInfo: wx.getStorageSync('user'),
  },
  isAuthenticated: false,

})